<?php
	$child_ul = $child_ul ? true : false;
	$route_item = empty($item['href']) ? false : Router::parse($item['href']);
	$submenu = $item->menu;
	$hasSubmenu = empty($submenu) ? false : true;
	$isCurrent = $route==$route_item && !$child_ul;
	
	// if ther's submenu which points to root-menu-item, check them
	if(!$child_ul && $hasSubmenu){
		foreach($submenu->item as $tmpItem) {
			if(Router::parse($tmpItem['href']) == $route) {
				$isCurrent = true;
				break;
			}
		}
	}
	
	$liClass="";
	if($hasSubmenu) $liClass .= " sub";
	if($isCurrent) $liClass .= " current";
	
	$liClass = trim($liClass);
	
	// parse item SimplXml object
	$a_item = (array)$item;
	$href = @$a_item['@attributes']['href']; $href=empty($href) ? 'javascript:void(0)' : $href;	
	$label = $a_item['@attributes']['label'];

	$user = $this->Session->read("Auth.User");
	
	$visible = true;
	if(isset($item['role'])){
		$roles = explode(" ", $item['role']);
		if(!in_array($user['role'], $roles) && $user['role']!="admin"){
			$visible=false;
		}
	}
?>
<? if($visible): ?>
<li<? if(!empty($liClass)): ?> class="<?= $liClass ?>"<? endif; ?>>
	<?= $this->Html->link($label, $href) ?>
	<? if($hasSubmenu): ?>
		<?= $this->element("menu", array("menu"=>$submenu, "child_ul"=>true, "parent"=>$item)) ?>
	<? endif; ?>
</li>
<? endif; ?>